package com.bjsxt;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@SpringBootApplication
@RestController
@RefreshScope // 配置的动态刷新
public class ConfigClientApplication {

    @Value("${user.name}")
    private String userName ;

    @Value("${user.age}")
    private Integer userAge ;

    @Value("${girl.name}") // no refresh test-b.yml
    private String girlName ;

    @Value("${girl.age}") // refresh test-a.yml
    private Integer girlAge ;

    public static void main(String[] args) {
        SpringApplication.run(ConfigClientApplication.class,args) ;
    }

    @GetMapping("/get/config")
    public ResponseEntity<String> config(){
        return ResponseEntity.ok("获取的配置信息为:"+userName+":"+userAge) ;
    }

    @GetMapping("/girl")
    public ResponseEntity<String> getGirl(){
       return ResponseEntity.ok(girlName+":"+girlAge) ;
    }
}
